package com.bt.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bt.mapper.DtsCouponMapper;
import com.bt.pojo.DtsCoupon;
import com.bt.service.DtsCouponService;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.util.Date;

/**
 * @author wbt
 * @version v1.0
 * @project shop_manage
 * @data 2022/9/26 10:42
 **/
@Service
public class DtsCouponServiceImpl implements DtsCouponService {
    @Autowired
    private DtsCouponMapper dtsCouponMapper;
    @Override
    public IPage<DtsCoupon> findDtsCouponByPage(Integer page, Integer limit, String name, Short type, Short status, String sort, String order) {
        return dtsCouponMapper.selectPage(new Page<DtsCoupon>(page,limit),new QueryWrapper<DtsCoupon>().eq(!StringUtils.isEmpty(name),"name",name).eq(type!=null?true:false,"type",type).eq(status!=null?true:false,"status",status).orderBy(!StringUtils.isEmpty(order),"desc".equals(order),sort));
    }

    @Override
    public DtsCoupon findDtsCouponById(Integer id) {
        return dtsCouponMapper.selectById(id);
    }

    @Override
    public void insertDtsCoupon(DtsCoupon dtsCoupon) {
        dtsCoupon.setAddTime(new Date());
        dtsCoupon.setUpdateTime(new Date());

        dtsCouponMapper.insert(dtsCoupon);
    }

    @Override
    public void deleteDtsCouponById(Integer id) {
        dtsCouponMapper.deleteById(id);
    }

    @Override
    public void updateDtsCouponById(DtsCoupon dtsCoupon) {
        dtsCoupon.setUpdateTime(new Date());
        dtsCouponMapper.updateById(dtsCoupon);
    }
}
